/*
 * MapLoader.cpp
 *
 *  Created on: May 25, 2011
 *      Author: madboyka
 */

#include "MapLoader.h"
#include "Entity.h"
#include "Logger.h"

MapLoader::MapLoader()
{
	parser = new EdlParser();
}

MapLoader::~MapLoader()
{
	delete parser;
}

bool MapLoader::load(const QString filename)
{
	parser->parseDocument(filename);
}

bool MapLoader::addObjects(World *world)
{
	QVectorIterator<Entity> it(*parser->getObjects());
	while (it.hasNext())
	{
		Entity entity = it.next();
		Logger::log("MapLoader: Addding %s to map!", entity.getType().toStdString().data());
		Obstacle* o = world->addObstacle(entity.getType().toStdString().data());
		o->setPosition(entity.getPos()[0], entity.getPos()[1], entity.getPos()[2]);
		o->setScale(entity.getScale()[0],entity.getScale()[1],entity.getScale()[2]);
		if (!entity.getMovable()) {
			o->setMass(1000);
		}
		o->createPhysics();
	}
	return true;
}

